/**
 * Created by dujiaheng on 2016/9/1.
 */

import * as FStorage from './FStorage'
import * as Config from '../url-config'

function fAjax(url, method, params, callback) {
    var timeout = Number(FStorage.getLocalItem('timeout'));
    url = Config.serverUrl() + url
    timeout = timeout ? timeout * 1000 : 3000;
    $.ajax({
        url: url,
        method: method,
        data: params,
        timeout: timeout,
        beforeSend: function () {
            //$.showPreloader();
            $.showIndicator();
        },
        complete: function () {
            //$.hidePreloader();
            $.hideIndicator();
        },
        error: function () {
            $.toast("网络异常");
        },
        success: callback
    });
}

export {fAjax}